package com.cqc.zxing01;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class MainActivity extends AppCompatActivity {

    @BindView(R.id.tv_code)
    TextView tvCode;
    private Context context;
    @BindView(R.id.btn1)
    Button btn1;
    @BindView(R.id.btn2)
    Button btn2;
    @BindView(R.id.btn3)
    Button btn3;
    @BindView(R.id.btn4)
    Button btn4;
    @BindView(R.id.btn5)
    Button btn5;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        context = this;
    }

    @OnClick({R.id.btn1, R.id.btn2, R.id.btn3, R.id.btn4, R.id.btn5})
    public void onViewClicked(View view) {
        Intent intent;
        switch (view.getId()) {
            case R.id.btn1://生成条形码
                intent = new Intent(this, CreateBarCodeActivity.class);
                startActivity(intent);
                break;
            case R.id.btn2:
                intent = new Intent(this, CreateQrCodeActivity.class);
                startActivity(intent);
                break;
            case R.id.btn3:
                intent = new Intent(this, ScanBarCodeActivity.class);
                startActivityForResult(intent, 1);
                break;
            case R.id.btn4:
                intent = new Intent(this, ScanQrCodeActivity.class);
                startActivityForResult(intent, 1);
                break;
            case R.id.btn5:
                intent = new Intent(this, ScanAllCodeActivity.class);
                startActivityForResult(intent, 1);
                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 1 && resultCode == 2) {
            String code = data.getStringExtra("BarCode");
            tvCode.setText(code);
            return;
        }
        if (requestCode == 1 && resultCode == 3) {
            String code = data.getStringExtra("QrCode");
            tvCode.setText(code);
            return;
        }
        if (requestCode == 1 && resultCode == 4) {
            String code = data.getStringExtra("AllCode");
            tvCode.setText(code);
            return;
        }
    }
}
